/*
 * @Description: 快速选择模态框
 * @Version: V1.0.0
 * @Autor: CHY
 * @Date: 2022-04-08 09:59:02
 * @LastEditors: CHY
 * @LastEditTime: 2022-04-08 22:49:42
 */
import React, { useEffect, useState } from 'react';
import { Checkbox } from 'antd';
import PubSub from 'pubsub-js';

import './index.css'
const FastSelect = (props) => {
    const [saveData, setSaveData] = useState([])//定义父组件传来数据状态
    //定义修改数据函数
    /*  function modifiData(id, state) {
         let arr=[]
         saveData.forEach(item => {
             if (item.id === id) {
                 item.flage = state
                 arr.push(item)
             } else {
                 arr.push(item)
             }
 
         });
     } */
    let timer = null
    function onChange(e, id, name) {
        const { headleSendData } = props.sendData
        e.stopPropagation()
        // console.log(e, id, name, e, "#################", headleSendData);
        /*  const value = saveData.find(item => {
             return item.id === id
         }) */

        const { cateName } = props.sendData
        timer = null
        timer = setTimeout(() => {
            if (e.target.checked === true) {
                // console.log('快速选择模态框value', name);
                headleSendData('e', { data: name, flage: true }, cateName, null)
            } else {
                headleSendData('e', { data: name, flage: false }, cateName, null)
            }
        }, 500)
    }
    useEffect(() => {
        const { assignedData } = props.sendData
        // console.log('快速选择模态框@@@@@@@@@@@@@@@', props);

        setSaveData(assignedData)
    }, [props]);
    return (
        <div className='fastSelect-container'>
            <div className='fastSelect-title'><h3>选择人员</h3></div>
            <div className='fastSelect-content'>
                {
                    saveData.map(item => {
                        return (
                            <div className='fastSelect-content-item' key={item.id}>
                                <div>{item.department}</div>
                                <div>{item.jobTitle === null ? '' : item.jobTitle.map(item2 => {
                                    return (
                                        <span key={item.id + parseInt(Math.random() * 100)} > < Checkbox onChange={(e, y) => onChange(e, item.id, item2)} >{item2}</Checkbox></span>
                                    )
                                })} </div>
                            </div>
                        )
                    })
                }

            </div>
        </div >
    );
}

export default FastSelect;
